###Space, Time, Space vs. Time#####
###02/24/2021######################
###TSCS literature review##################

setwd(dirname(rstudioapi::getActiveDocumentContext()$path))


#Get packages, attach them
pks=c("ggplot2", "dplyr")
needed=setdiff(pks,installed.packages())

if( length(needed) > 0){
  options(Ncpus=parallel::detectCores() %/% 1.25)
  install.packages(needed)
}

sapply(pks, library, character.only=T)
session = sessionInfo()


TSCS <- read.csv("Top_3_Journals_count_1980_2019.csv", header=T)

TSCS$TSCS_DATA <- ifelse(TSCS$time.series.cross.section > 0 | TSCS$panel.data >0 |TSCS$tscs > 0 ,1,0)
TSCS <- TSCS[which(TSCS$TSCS_DATA == 1), ]

TSCS$TS_ANY <- ifelse(TSCS$time.series > 0 | TSCS$time.serial > 0 | TSCS$time.lagged > 0 | TSCS$time.lagged.dependent > 0 | TSCS$temporal.autocorrelation > 0 | TSCS$temporal.correlation > 0 | TSCS$temporal.dependence > 0 | TSCS$temporal.dynamics > 0 | TSCS$time.dependence > 0 | TSCS$time.lag > 0  | TSCS$serial.correlation >0 | TSCS$serially.correlated > 0 | TSCS$serial.dependence > 0,1,0)
TSCS$SP_ANY <- ifelse(TSCS$spatial.lag > 0 |TSCS$spatial.dependence > 0| TSCS$spatial.correlation > 0 | TSCS$spatially.correlated > 0 | TSCS$spatial.lag.dependent > 0 | TSCS$spatially.lagged > 0 | TSCS$spatially.lagged.dependent > 0,1,0)

TSCS <- TSCS[c("Year","TSCS_DATA","TS_ANY","SP_ANY")]

TSCS <- TSCS %>% rename(TSCS = TSCS_DATA, Temporal = TS_ANY, Spatial = SP_ANY )
TSCS_annual <- TSCS%>%group_by(Year)%>%summarise_all(funs(sum))
TSCS_annual <- melt(TSCS_annual, id="Year")
TSCS_annual <- TSCS_annual %>% rename(Type = variable)


ggplot(data=TSCS_annual,
       aes(x=Year, y=value, linetype=Type)) +
  ylab("Articles") +
   theme_bw() + 
  geom_line()

ggsave("Figure1.pdf", height=4, width=6, units="in", dpi=600)
